package fr.tvbarthel.games.chasewhisply.ui.fragments;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import java.util.ArrayList;

import fr.tvbarthel.games.chasewhisply.R;
import fr.tvbarthel.games.chasewhisply.model.PlayerProfile;
import fr.tvbarthel.games.chasewhisply.model.bonus.BonusEntry;
import fr.tvbarthel.games.chasewhisply.model.bonus.BonusEntryFactory;
import fr.tvbarthel.games.chasewhisply.model.inventory.InventoryItemInformation;
import fr.tvbarthel.games.chasewhisply.model.mode.GameMode;
import fr.tvbarthel.games.chasewhisply.model.mode.GameModeFactory;
import fr.tvbarthel.games.chasewhisply.ui.adapter.GameModeViewAdapter;
import fr.tvbarthel.games.chasewhisply.ui.customviews.GameModeView;
import fr.tvbarthel.games.chasewhisply.ui.gameviews.HTextView;

import static fr.tvbarthel.games.chasewhisply.model.bonus.BonusEntryFactory.*;
import static fr.tvbarthel.games.chasewhisply.model.mode.GameModeFactory.createTwentyInARow;


public class BatNightFragment extends Fragment implements AdapterchooseListenter ,View.OnClickListener{

    private IStartActivityListener mListener;

    private HTextView mIntroductionView ;

    private PlayerProfile mPlayerProfile ;

    public BatNightFragment()
    {
    }

    public interface Listener {
        public void onLevelChosen(GameModeView g);
    }

    public void beginBatNightGame( )
    {
        mIntroductionView.StopTyper();
        BonusEntry bonusEntry = create(InventoryItemInformation.TYPE_STEEL_BULLET, mPlayerProfile.getSteelBulletQuantity());
        GameMode gameMode = GameModeFactory.createTwentyInARow( 1) ;
        gameMode.setBonus( bonusEntry.getBonus() );
        mListener.onGameStartRequest( gameMode );

    }

    @Override
    public void onClick(View view) {
      
        switch (view.getId()) {
            case R.id.fastforword:
               // mListener.onStartGameRequested();
                break;
            case R.id.Restart:
                beginBatNightGame() ;
                break;
            default:
                break;
        }
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        // textView1.animateText(getString(R.string.));
        if (activity instanceof IStartActivityListener) {
            mListener = (IStartActivityListener) activity;
            mPlayerProfile = new PlayerProfile(activity.getSharedPreferences(
                    PlayerProfile.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE));
        } else {
            throw new ClassCastException(activity.toString()
                    + " must implement GameModeChooserFragment.Listener");
        }
    }

    @Override
    public void onDetach() {

        super.onDetach();

        mListener = null;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View v = inflater.inflate(R.layout.fragment_batnight, container, false);
        final int[] clickable = new int[]{
                R.id.fastforword,
                R.id.Restart

        };
        IntroductionAnimation(v);

        for (int i : clickable) {
            final View view = v.findViewById(i);
            view.setOnClickListener(this);
        }
        return v;
    }

    private void IntroductionAnimation(View v)
    {
        mIntroductionView = (HTextView) v.findViewById(R.id.batnightIntroduction);

        CInstroductionAnimationLisenter introductionlisenter = new CInstroductionAnimationLisenter( this) ;

        mIntroductionView.setAnimationListener( introductionlisenter);

        mIntroductionView.animateText("字体滚动，逐渐............................................................................................显示，幽灵王在万圣节将要进攻人类，" +
                "派遣黑蝙蝠打探人间消息，为了保护人类，你需要移动手机找到这些蝙"+
                        "蝠，迅速将他们杀死，需要将这些黑蝙蝠都杀死");
    }


    @Override
    public void onGameModeSelected(GameModeView view) {
        //mListener.onLevelChosen(view);
    }
}
